package com.cf.domain;

import lombok.Data;

import javax.servlet.http.HttpServletResponse;

@Data
public class ResponseResult<T> {

    private int code;

    private String errorCode;

    private String message;

    private T data;

    public static<T> ResponseResult<T> sucess(){
        return sucess(HttpServletResponse.SC_OK, null, null);
    }

    public static<T> ResponseResult<T> sucess(T data){
        return sucess(HttpServletResponse.SC_OK, null, data);
    }

    public static<T> ResponseResult<T> sucess(int code, String message, T data){
        ResponseResult<T> resp = new ResponseResult<>();
        resp.setCode(code);
        resp.setMessage(message);
        resp.setData(data);

        return resp;
    }

    public static<T> ResponseResult<T> fail(int code, String errorCode, String message, T data){
        ResponseResult<T> resp = new ResponseResult<>();
        resp.setCode(code);
        resp.setErrorCode(errorCode);
        resp.setMessage(message);
        resp.setData(data);

        return resp;
    }

    public static<T> ResponseResult<T> fail(String message){
        return fail(HttpServletResponse.SC_OK, null, message, null);
    }
    public static<T> ResponseResult<T> fail(String errorCode, String message){
        return fail(HttpServletResponse.SC_OK, errorCode, message, null);
    }
    public static<T> ResponseResult<T> fail(int code, String errorCode, String message){
        return fail(code, errorCode, message, null);
    }
}
